﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace CPPProject.Migrations
{
    public partial class AddCPPModel : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "CPPAttachment",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    FileName = table.Column<string>(maxLength: 50, nullable: false),
                    FileData = table.Column<byte[]>(nullable: true),
                    FileExtension = table.Column<string>(maxLength: 10, nullable: false),
                    FileSize = table.Column<decimal>(nullable: false),
                    ObjectName = table.Column<string>(maxLength: 50, nullable: false),
                    ObjectId = table.Column<string>(maxLength: 50, nullable: false),
                    ObjectField = table.Column<string>(maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPAttachment", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CPPCategory",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CreatorUserId = table.Column<long>(nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CategoryName = table.Column<string>(maxLength: 50, nullable: false),
                    CategoryIndex = table.Column<string>(maxLength: 50, nullable: false),
                    Layout = table.Column<string>(maxLength: 50, nullable: false),
                    ParentId = table.Column<int>(nullable: false),
                    Childs = table.Column<int>(nullable: false),
                    Level = table.Column<int>(nullable: false),
                    IsHide = table.Column<bool>(nullable: false),
                    Icons = table.Column<string>(maxLength: 50, nullable: true),
                    Remark = table.Column<string>(maxLength: 500, nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    OrderId = table.Column<int>(nullable: false),
                    IsRec = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPCategory", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CPPCompany",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    Address = table.Column<string>(maxLength: 500, nullable: false),
                    Address2 = table.Column<string>(maxLength: 500, nullable: true),
                    Address3 = table.Column<string>(maxLength: 500, nullable: true),
                    Contactor = table.Column<string>(maxLength: 50, nullable: false),
                    Contactor2 = table.Column<string>(maxLength: 50, nullable: true),
                    Contactor3 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 50, nullable: false),
                    Telphone2 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone3 = table.Column<string>(maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPCompany", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CPPRoleMenu",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    Path = table.Column<string>(maxLength: 500, nullable: true),
                    Component = table.Column<string>(maxLength: 500, nullable: true),
                    Icon = table.Column<string>(maxLength: 100, nullable: true),
                    OrderNum = table.Column<int>(nullable: false),
                    Hidden = table.Column<bool>(nullable: false),
                    ParentId = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPRoleMenu", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CPPAccount",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    ParentId = table.Column<int>(nullable: false),
                    IsDeleted = table.Column<bool>(nullable: false),
                    UserName = table.Column<string>(maxLength: 50, nullable: false),
                    Password = table.Column<string>(maxLength: 50, nullable: false),
                    CompanyId = table.Column<long>(nullable: false),
                    UserId = table.Column<long>(nullable: true),
                    MenuRights = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPAccount", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPAccount_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPCarrier",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: false),
                    CompanyId = table.Column<long>(nullable: false),
                    CarrierNum = table.Column<string>(maxLength: 50, nullable: false),
                    CarrierID = table.Column<string>(maxLength: 100, nullable: true),
                    Address = table.Column<string>(maxLength: 500, nullable: false),
                    Address2 = table.Column<string>(maxLength: 500, nullable: true),
                    Address3 = table.Column<string>(maxLength: 500, nullable: true),
                    Contactor = table.Column<string>(maxLength: 50, nullable: false),
                    Contactor2 = table.Column<string>(maxLength: 50, nullable: true),
                    Contactor3 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 50, nullable: false),
                    Telphone2 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone3 = table.Column<string>(maxLength: 50, nullable: true),
                    CreditCode = table.Column<string>(maxLength: 300, nullable: true),
                    RegistCapital = table.Column<decimal>(nullable: false),
                    LegalPerson = table.Column<string>(maxLength: 50, nullable: true),
                    TaxNumber = table.Column<string>(maxLength: 50, nullable: true),
                    OpeningBank = table.Column<string>(maxLength: 50, nullable: true),
                    OpeningAccount = table.Column<string>(maxLength: 50, nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false),
                    CarriageContract = table.Column<string>(maxLength: 500, nullable: true),
                    ImageUrl = table.Column<string>(maxLength: 500, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPCarrier", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPCarrier_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });        
            migrationBuilder.CreateTable(
                name: "CPPCustomer",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: false),
                    CompanyId = table.Column<long>(nullable: false),
                    CustNum = table.Column<string>(maxLength: 50, nullable: false),
                    Address = table.Column<string>(maxLength: 500, nullable: false),
                    Address2 = table.Column<string>(maxLength: 500, nullable: true),
                    Address3 = table.Column<string>(maxLength: 500, nullable: true),
                    Contactor = table.Column<string>(maxLength: 50, nullable: false),
                    Contactor2 = table.Column<string>(maxLength: 50, nullable: true),
                    Contactor3 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 50, nullable: false),
                    Telphone2 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone3 = table.Column<string>(maxLength: 50, nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false),
                    Email = table.Column<string>(maxLength: 300, nullable: true),
                    Group = table.Column<string>(maxLength: 50, nullable: true),
                    Saler = table.Column<string>(maxLength: 50, nullable: true),
                    TaxNumber = table.Column<string>(maxLength: 50, nullable: true),
                    OpeningBank = table.Column<string>(maxLength: 300, nullable: true),
                    OpeningAccount = table.Column<string>(maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPCustomer", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPCustomer_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPOrderHed",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CompanyId = table.Column<long>(nullable: false),
                    OrderNum = table.Column<string>(maxLength: 50, nullable: false),
                    ContractNum = table.Column<string>(maxLength: 50, nullable: false),
                    CustNum = table.Column<string>(maxLength: 50, nullable: false),
                    OrderDate = table.Column<DateTime>(nullable: false),
                    DueDate = table.Column<DateTime>(nullable: false),
                    Status = table.Column<string>(maxLength: 10, nullable: true),
                    FromPlantId = table.Column<string>(maxLength: 50, nullable: true),
                    ToPlantId = table.Column<string>(maxLength: 50, nullable: true),
                    IType = table.Column<string>(maxLength: 10, nullable: true),
                    Remark = table.Column<string>(maxLength: 300, nullable: true),
                    ApplyReason = table.Column<string>(maxLength: 300, nullable: true),
                    OtherRequire = table.Column<string>(maxLength: 300, nullable: true),
                    ProjectName = table.Column<string>(maxLength: 50, nullable: true),
                    Address = table.Column<string>(maxLength: 300, nullable: true),
                    Contactor = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 50, nullable: true),
                    TransMode = table.Column<string>(maxLength: 50, nullable: true),
                    CarId = table.Column<string>(maxLength: 50, nullable: true),
                    DriverPhone = table.Column<string>(maxLength: 50, nullable: true),
                    BusType = table.Column<string>(maxLength: 10, nullable: true),
                    NDays = table.Column<int>(nullable: false),
                    ApproveUser = table.Column<string>(maxLength: 50, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPOrderHed", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPOrderHed_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPPart",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CompanyId = table.Column<long>(nullable: false),
                    PartNum = table.Column<string>(maxLength: 50, nullable: false),
                    Name = table.Column<string>(maxLength: 500, nullable: false),
                    Description = table.Column<string>(maxLength: 500, nullable: true),
                    ImageUrl = table.Column<string>(maxLength: 500, nullable: true),
                    Quantity = table.Column<decimal>(nullable: false),
                    MtlCost = table.Column<decimal>(nullable: false),
                    IUM = table.Column<string>(maxLength: 10, nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPPart", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPPart_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPPartTrans",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CompanyId = table.Column<long>(nullable: false),
                    TransNum = table.Column<string>(maxLength: 50, nullable: false),
                    PartNum = table.Column<string>(maxLength: 50, nullable: false),
                    OrderNum = table.Column<string>(maxLength: 50, nullable: false),
                    ContractNum = table.Column<string>(maxLength: 50, nullable: false),
                    Status = table.Column<string>(maxLength: 10, nullable: true),
                    FromPlantId = table.Column<string>(maxLength: 300, nullable: true),
                    ToPlantId = table.Column<string>(maxLength: 300, nullable: true),
                    OrderDate = table.Column<DateTime>(nullable: false),
                    DeliveryDate = table.Column<DateTime>(nullable: false),
                    CarrierNum = table.Column<string>(maxLength: 50, nullable: true),
                    CarrierId = table.Column<int>(nullable: false),
                    CustNum = table.Column<string>(maxLength: 50, nullable: true),
                    CustId = table.Column<long>(nullable: false),
                    StatusChangeDate = table.Column<DateTime>(nullable: true),
                    StatusChangeUser = table.Column<string>(maxLength: 300, nullable: true),
                    IType = table.Column<string>(maxLength: 10, nullable: true),
                    Remark = table.Column<string>(maxLength: 300, nullable: true),
                    DriverName = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 300, nullable: true),
                    CarId = table.Column<string>(maxLength: 300, nullable: true),
                    Quantity = table.Column<decimal>(nullable: false),
                    UnitPrice = table.Column<decimal>(nullable: false),
                    Amount = table.Column<decimal>(nullable: false),
                    RelationData = table.Column<string>(maxLength: 300, nullable: true),
                    SendDate = table.Column<DateTime>(nullable: true),
                    TransMode = table.Column<string>(maxLength: 10, nullable: true),
                    DriverPhone = table.Column<string>(maxLength: 300, nullable: true),
                    ProjectName = table.Column<string>(maxLength: 300, nullable: true),
                    BusType = table.Column<string>(maxLength: 10, nullable: true),
                    CreateByOrder = table.Column<string>(maxLength: 300, nullable: true),
                    NDays = table.Column<int>(maxLength: 300, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPPartTrans", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPPartTrans_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPPlant",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CompanyId = table.Column<long>(nullable: false),
                    PlantId = table.Column<string>(maxLength: 50, nullable: true),
                    Name = table.Column<string>(maxLength: 50, nullable: true),
                    Address = table.Column<string>(maxLength: 500, nullable: true),
                    Longitude = table.Column<string>(maxLength: 300, nullable: true),
                    Latitude = table.Column<string>(maxLength: 300, nullable: true),
                    CustomerId = table.Column<string>(maxLength: 300, nullable: true),
                    ParentId = table.Column<int>(nullable: false),
                    Contactor = table.Column<string>(maxLength: 50, nullable: true),
                    Contactor2 = table.Column<string>(maxLength: 50, nullable: true),
                    Contactor3 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone2 = table.Column<string>(maxLength: 50, nullable: true),
                    Telphone3 = table.Column<string>(maxLength: 50, nullable: true),
                    IsEnabled = table.Column<bool>(nullable: false),
                    MaxCapacity = table.Column<string>(maxLength: 300, nullable: true),
                    IVirtual = table.Column<bool>(nullable: false),
                    IType = table.Column<string>(maxLength: 300, nullable: true),
                    IsBin = table.Column<bool>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPPlant", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPPlant_CPPCompany_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "CPPCompany",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPOrderDtl",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    CompanyId = table.Column<long>(nullable: false),
                    OrderNum = table.Column<string>(maxLength: 50, nullable: false),
                    PartNum = table.Column<string>(maxLength: 50, nullable: false),
                    PartId = table.Column<Guid>(nullable: false),
                    Quantity = table.Column<decimal>(nullable: false),
                    UnitPriice = table.Column<decimal>(nullable: false),
                    LineAmount = table.Column<decimal>(nullable: false),
                    TaxRate = table.Column<decimal>(nullable: false),
                    Status = table.Column<string>(maxLength: 10, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPOrderDtl", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPOrderDtl_CPPPart_PartId",
                        column: x => x.PartId,
                        principalTable: "CPPPart",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CPPPartBOM",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    TenantId = table.Column<int>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    PartNum = table.Column<string>(maxLength: 50, nullable: false),
                    PartId = table.Column<Guid>(nullable: false),
                    ParentId = table.Column<Guid>(nullable: true),
                    Quantity = table.Column<decimal>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CPPPartBOM", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CPPPartBOM_CPPPart_PartId",
                        column: x => x.PartId,
                        principalTable: "CPPPart",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CPPAccount_CompanyId",
                table: "CPPAccount",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPCarrier_CompanyId",
                table: "CPPCarrier",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPCustomer_CompanyId",
                table: "CPPCustomer",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPOrderDtl_PartId",
                table: "CPPOrderDtl",
                column: "PartId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPOrderHed_CompanyId",
                table: "CPPOrderHed",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPPart_CompanyId",
                table: "CPPPart",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPPartBOM_PartId",
                table: "CPPPartBOM",
                column: "PartId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPPartTrans_CompanyId",
                table: "CPPPartTrans",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPPlant_CompanyId",
                table: "CPPPlant",
                column: "CompanyId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "CPPAccount");

            migrationBuilder.DropTable(
                name: "CPPAttachment");

            migrationBuilder.DropTable(
                name: "CPPCarrier");

            migrationBuilder.DropTable(
                name: "CPPCategory");

            migrationBuilder.DropTable(
                name: "CPPCustomer");

            migrationBuilder.DropTable(
                name: "CPPOrderDtl");

            migrationBuilder.DropTable(
                name: "CPPOrderHed");

            migrationBuilder.DropTable(
                name: "CPPPartBOM");

            migrationBuilder.DropTable(
                name: "CPPPartTrans");

            migrationBuilder.DropTable(
                name: "CPPPlant");

            migrationBuilder.DropTable(
                name: "CPPRoleMenu");

            migrationBuilder.DropTable(
                name: "CPPPart");

            migrationBuilder.DropTable(
                name: "CPPCompany");
        }
    }
}
